<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Base class for Limited Textarea
 * 
 * 用来显示一个限制文本的控件.
 * MUST includes the 'charCount' js lib.
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.1
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_widget.php';

// Definitions.

/**
 * Widget for displaying LimitedTextarea.
 */
class LimitedTextarea extends Widget
{
	/**
	 * The id of the counter.
	 */
	var $counterid;
	
	/**
	 * The id of the textarea.
	 */
	var $textareaid;
	
	/**
	 * The counter of the limitation.
	 */
	var $allowed;
	
	/**
	 * Constructor.
	 */
	function __construct($counterid,
						 $textareaid,
						 $allowed,
						 $out,
						 $args = array())
	{
		parent::__construct($out, $out->args);
		
		$this->counterid = $counterid;
		$this->textareaid = $textareaid;
		$this->allowed = $allowed;
	}
	
	/**
	 * Preparation for the initialization.
	 */
	function prepareData()
	{
		$this->out->hidden('charCount_allowed', $this->allowed);
	}
	
	
	/**
	 * Show the limited textarea.
	 */
	function show()
	{
		$this->out->elementStart('p', 'cls_p_charcounter');
		$this->out->text('您还可以输出');
		$this->out->element('span', array('id' => $this->counterid,
										  'class' => 'cls_charCount_counter'));
		$this->out->text('个字.');
		$this->out->elementEnd('p');
		
		$this->out->elementStart('div');
		$this->out->textarea($this->textareaid,
							 '简短的几句话: ',
							 4,
							 60,
							 $this->getField($this->textareaid),
							 '这个是微型版本呢亲.');
		$this->out->elementEnd('div');			
	}
}

?>